<?php

namespace App\Trip\Plane\Rules;

use App\Models\Plane\Rules\PlaneLuggageRule;
use App\Trip\Plane\Requests\RulesRequest;
use App\Trip\Plane\Rules\Interfaces\LuggageRuleInterface;
use Exception;

class SystemLuggageRule implements LuggageRuleInterface
{
    /**
     * @var array
     */
    private array        $rules;
    private RulesRequest $request;

    /**
     * @throws Exception
     */
    public function __construct(RulesRequest $request)
    {
        $cr            = new PlaneLuggageRule();
        $this->request = $request;
        $this->rules   = $cr->findByCarrierCode($request->getCarrierCode())->toArray();
    }

    public function getLuggageRemark(): string
    {
        return 'TODO';
    }

    public function getLuggageDetails(): array
    {
        $rules = [];
        foreach ($this->rules as $rule) {
            $rule_key         = "{$rule['cabin_name']}{$rule['cabin_code']}";
            $rules[$rule_key] = [
                'checked' => [
                    'weight' => $rule['checked_weight'],
                    'volume' => (new ParseLuggageVolume($rule['checked_volume']))->toArray(),
                    'number' => $rule['checked_number'],
                ],
                'carry'   => [
                    'weight'        => $rule['carry_weight'],
                    'single_weight' => $rule['carry_single_weight'],
                    'volume'        => (new ParseLuggageVolume($rule['carry_volume']))->toArray(),
                    'number'        => $rule['carry_number'],
                ],
                'baby'    => [
                    'desc'     => $rule['baby_desc'],
                    'desc_uy ' => $rule['baby_desc_uy'],
                    'checked'  => [
                        'weight'   => '',
                        'volume'   => [
                            'limit'   => '',
                            'desc'    => '',
                            'desc_uy' => '',
                        ],
                        'pram_num' => '',
                    ],
                ],
            ];
        }

        $match_key = '';
        return $rules[$match_key] ?? [];
    }

    public function getLuggageRemarkUy(): string
    {
        return '';
    }
}